/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bashe.common.util;

import han.bashe.common.config.Config;
import han.bashe.common.entity.BifangEntityConstants;

import java.util.HashMap;

/**
 * @Author Kent
 */
public class QosUtil {
	public static final int YES = 1;
	public static final int NO = -1;
	public static final int DEFAULT = 0;
	
	
	/**
	 * 
	 * @param qos
	 * @return 1 yes
	 *         0 default
	 *         -1 no
	 */
	public static int isLogEnable(HashMap<String ,String> qos){
		if(qos.get(BifangEntityConstants.QOS_LOG).equals(BifangEntityConstants.QOS_YES))
			return 1;
		else if(qos.get(BifangEntityConstants.QOS_LOG).equals(BifangEntityConstants.QOS_NO))
			return -1;
		else
			return 0;
	}
	
	/**
	 * 
	 * @param qos
	 * @return 1 yes
	 *         0 default
	 *         -1 no
	 */
	public static int isSecurityEnable(HashMap<String ,String> qos){
		if(qos.get(BifangEntityConstants.QOS_ACL).equals(BifangEntityConstants.QOS_YES))
			return 1;
		else if(qos.get(BifangEntityConstants.QOS_ACL).equals(BifangEntityConstants.QOS_NO))
			return -1;
		else
			return 0;
	}
	
	/**
	 * 
	 * @param qos
	 * @return 1 yes
	 *         0 default
	 *         -1 no
	 */
	public static int isRetryEnable(HashMap<String ,String> qos){
		if(qos.get(BifangEntityConstants.QOS_RETRY).equals(BifangEntityConstants.QOS_YES))
			return 1;
		else if(qos.get(BifangEntityConstants.QOS_RETRY).equals(BifangEntityConstants.QOS_NO))
			return -1;
		else
			return 0;
	}
	
	public static String getCommonType(HashMap<String, String> qos){
		return qos.get(BifangEntityConstants.QOS_COMM_TYPE);
	}
	
	public static int getTimeout(HashMap<String, String> qos){
		String s = qos.get(BifangEntityConstants.QOS_TIMEOUT);
		if(s == null){
			return Config.DEFAULT_SERVICE_TIMEOUT;
		}else{
			int i = Integer.parseInt(s);
			return i < 0 ? Config.DEFAULT_SERVICE_TIMEOUT : i;
		}
		
	}
	
	

}
